﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Wook4_一元二次方程
{
    class Program
    {
        static void Main(string[] args) { try { int d; double x1, x2; Console.WriteLine("请输入方程ax²+bx+c中a、b、c的值："); int a = Convert.ToInt32(Console.ReadLine()); int b = Convert.ToInt32(Console.ReadLine()); int c = Convert.ToInt32(Console.ReadLine()); d = b * b - 4 * a * c; if (d >= 0) { if (d == 0) { x1 = -(b / (2 * a)); Console.WriteLine("方程有且只有一个解,解为{0}", x1); } else { x1 = (-b + Math.Sqrt(d)) / 2.0 * a; x2 = (-b - Math.Sqrt(d)) / 2.0 * a; Console.WriteLine("方程有两个解,分别为{0}和{1}", x1, x2); } } else { Console.WriteLine("方程无解"); } } catch (Exception) { Console.WriteLine("输入格式有误！"); } Console.ReadKey(); }
    }
}
